package testGameObjects;

import static org.junit.Assert.*;

import org.junit.*;

import YAPserver.gameObjects.Line;
import YAPserver.gameObjects.Point;

public class TestLine {
	Line line1;
	Line line2;
	Line line3;
	Line line4;
	Point point1;
	Point point2;
	@Before
	public void setup() throws Exception{
		line1 = new Line(6, Math.PI/4, new Point(0,0));
		line2 = new Line(Math.sqrt(2), 3*Math.PI/4, new Point(4, 1));
		line4 = new Line(new Point(0,0), new Point(1,1));
		
		point1 = new Point(7, 8);
		point2 = new Point(5, 10);
		line3 = new Line(point1, point2); 
	}
	
	@Test
	public void testAngleBetweenLines(){
		//result should be PI/2
		assertTrue(line1.angleBetweenLines(line3)==Math.PI/2);
	}
	
	@Test
	public void testEndPoint(){
		double x = line2.getEndPoint().getXPos();
		double y = line2.getEndPoint().getYPos();
		assertTrue(x==3);
		assertTrue(y==2);
	}
	public void testStartPoint(){
		line3.setEndPoint(new Point(0,0));
		double x = line3.getStartPoint().getXPos();
		double y = line3.getStartPoint().getYPos();
		assertTrue(x==-2);
		assertTrue(y==-2);
	}
	
	@Test
	public void testHasNoIntersection(){
		assertFalse(line1.hasIntersection(line2));
	}
	
	@Test
	public void testHasIntersection() throws Exception{
		line2.setStartPoint(new Point(3,1));
		assertTrue(line1.hasIntersection(line2));
		line2.setStartPoint(new Point(2,1));
		assertTrue(line1.hasIntersection(line2));
		line2.setStartPoint(new Point(1,1));
		assertTrue(line1.hasIntersection(line2));
	}
	@Test
	public void testIntersectionPoint(){
		Point p = line4.intersect(new Line(new Point(-1, 0), new Point(0,1)));
		assertTrue(p==null);
		p = line4.intersect(new Line(new Point(0, 1), new Point(-1,0)));
//		System.out.println("X: " + p.getXPos() + " Y: "+p.getYPos());
		assertTrue(p==null);
	}
}
